home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / X11.TRM < prev   
Text File  |  1992-03-25  |  4KB  |  131 lines

  1. /*
  2.  * $Id: x11.trm,v 3.26 92/03/24 22:35:49 woo Exp Locker: woo $
  3.  */
  4.  
  5. /*
  6.  *    x11.trm  --- inboard terminal driver for X11
  7.  */
  8.  
  9. #define X11_XMAX 4096
  10. #define X11_YMAX 4096
  11.  
  12. /* approximations for typical font/screen sizes */
  13. #define X11_VCHAR (X11_YMAX/25) 
  14. #define X11_HCHAR (X11_XMAX/100) 
  15. #define X11_VTIC (X11_YMAX/100)
  16. #define X11_HTIC (X11_XMAX/150)
  17.  
  18. #define X11_nopts 25
  19. char X11_opts[X11_nopts][20] = {
  20.    "-mono", "-gray", "-clear",
  21.    "-iconic", "-rv", "-reverse", "+rv", "-synchronous", 
  22.    "-display", "-geometry", "-bg", "-background", "-bd", "-bordercolor", "-bw",
  23.    "-borderwidth", "-fg", "-foreground", "-fn", "-font", "-name", 
  24.    "-selectionTimeout", "-title", "-xnllanguage", "-xrm" 
  25.    };
  26. int X11_optarg[X11_nopts] = { 
  27.    0, 0, 0,
  28.    0, 0, 0, 0, 0,
  29.    1, 1, 1, 1, 1, 1, 1,
  30.    1, 1, 1, 1, 1, 1, 
  31.    1, 1, 1, 1
  32.    };
  33.  
  34. FILE *X11_ipc; 
  35. char X11_command[1024]= "gnuplot_x11";
  36.  
  37. /*   X11_args - scan gnuplot command line for standard X Toolkit options */
  38.  
  39. X11_args(argc, argv) int argc; char *argv[]; {
  40.    int nx11 = 0, n;
  41.  
  42.    while(++argv, --argc > 0) {
  43.       for (n=0; n<X11_nopts; n++) {
  44.      if (!strcmp(*argv, X11_opts[n])) {
  45.         strcat(X11_command, " ");
  46.         strcat(X11_command, *argv); 
  47.         if (X11_optarg[n]) {
  48.            if (--argc <= 0) return(nx11);
  49.            strcat(X11_command, " \"");
  50.            strcat(X11_command, *++argv); 
  51.            strcat(X11_command, "\"");
  52.            nx11++;
  53.            }
  54.         nx11++; break;
  55.         }
  56.      }
  57.       if (n == X11_nopts) break; 
  58.       }
  59.    return(nx11);
  60.    }
  61.  
  62. #ifndef CRIPPLED_SELECT
  63. /*-----------------------------------------------------------------------------
  64.  *   use pipe IPC on most platforms
  65.  *---------------------------------------------------------------------------*/
  66. FILE *popen();
  67.  
  68. X11_init() { X11_ipc = popen(X11_command, "w"); }
  69.  
  70. X11_graphics() { fprintf(X11_ipc, "G\n"); }
  71.  
  72. X11_text() { 
  73.    fprintf(X11_ipc, "E\n"); fflush(X11_ipc);
  74. #ifdef ULTRIX_KLUDGE
  75.    fprintf(X11_ipc, "E\n"); fflush(X11_ipc);
  76. #endif
  77.    }
  78.  
  79. X11_reset() { fprintf(X11_ipc, "R\n"); fflush(X11_ipc); pclose(X11_ipc); }
  80.  
  81. #else   /* CRIPPLED_SELECT */
  82. /*-----------------------------------------------------------------------------
  83.  *   use file IPC on the others
  84.  *---------------------------------------------------------------------------*/
  85.  
  86. char X11_tmp[32], X11_tmp0[32], X11_shutdown[32];
  87. int X11_pid;
  88.  
  89. X11_init() { 
  90.    if (!(X11_pid = fork())) {
  91.       execl("/bin/sh", "sh", "-c", X11_command, NULL);
  92.       _exit(1);
  93.       }
  94.    sprintf(X11_tmp, "/tmp/Gnuplot_%d", X11_pid);
  95.    sprintf(X11_tmp0, "%s-", X11_tmp);
  96.    sprintf(X11_shutdown,  "echo R >%s",X11_tmp);
  97.    }
  98.  
  99. X11_graphics() { 
  100.    X11_ipc = fopen(X11_tmp0, "w"); 
  101.    if (!X11_ipc) { perror(X11_tmp0); system(X11_shutdown); exit(1); }
  102.    fprintf(X11_ipc, "G\n"); 
  103.    }
  104.  
  105. X11_text() { 
  106.    fprintf(X11_ipc, "E\n"); 
  107. #ifdef ULTRIX_KLUDGE
  108.    fprintf(X11_ipc, "E\n");
  109. #endif
  110.    fclose(X11_ipc);
  111.    rename(X11_tmp0, X11_tmp);
  112.    }
  113.  
  114. X11_reset() { system(X11_shutdown); }
  115.  
  116. #endif  /* CRIPPLED_SELECT */ /*---------------------------------------------*/
  117.  
  118. X11_move(x,y) unsigned int x,y; { fprintf(X11_ipc, "M%04d%04d\n", x, y); }
  119.  
  120. X11_vector(x,y) unsigned int x,y; { fprintf(X11_ipc, "V%04d%04d\n", x, y); }
  121.  
  122. X11_linetype(lt) int lt; { fprintf(X11_ipc, "L%04d\n", lt); }
  123.  
  124. X11_put_text(x,y,str) unsigned int x,y; char str[]; {
  125.    fprintf(X11_ipc, "T%04d%04d%s\n", x, y, str);
  126.    }
  127. X11_justify_text(mode) enum JUSTIFY mode; {
  128.    fprintf(X11_ipc, "J%04d\n", mode);
  129.    return(TRUE);
  130.    }
  131.